﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lily.Admin
{
    public partial class Dictionary : System.Web.UI.Page
    {
        private LilyDataContext lilyDC;
        private void DDLBind()
        {
            var type = from a in lilyDC.Dictionary where a.typeID == 0 select a;
            DDLType.DataSource = type;
            DDLType.DataTextField = "name";
            DDLType.DataValueField = "ID";
            DDLType.DataBind();
            btnSearch_Click(null, null);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            lilyDC = new LilyDataContext();
            if (!IsPostBack)
            {
                DDLBind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            var foo = from a in lilyDC.Dictionary where a.typeID.ToString() == DDLType.SelectedValue select a;
            rptDic.DataSource = foo;
            rptDic.DataBind();
        }

        protected void btnModuleAdd_Click(object sender, EventArgs e)
        {
            var bar = (from a in lilyDC.Dictionary where a.typeID == 0 select a.value).Max();
            Lily.Dictionary foo = new Lily.Dictionary {name = txtModuleName.Text, typeID = 0, value = bar+1};
            lilyDC.Dictionary.InsertOnSubmit(foo);
            lilyDC.SubmitChanges();
            DDLBind();
        }
    }
}
